<template>
  <div
    class="navigation-bar-container"
    :class="{
      defaultBg: !transparent,
      transparent: transparent,
      'border-bottom': borderBottom,
    }"
  >
    <div class="navi-box left-box">
      <i class="iconfont icon-back" v-if="back" @click="goBack">返回</i>
      <slot name="left"></slot>
    </div>
    <template v-if="title">
      <span class="title">
        {{ title }}
      </span>
    </template>
    <template v-else>
      <slot name="title"></slot>
    </template>
    <template v-if="search">
      <search-input
        class="search"
        @change="handleChange"
        :searchVal="searchVal"
      ></search-input>
    </template>
    <div class="navi-box right-box" @click="clickRigth">
      <slot name="right"></slot>
    </div>
  </div>
</template>

<script>
import SearchInput from '../SearchInput'
export default {
  components: {
    SearchInput,
  },
  props: {
    title: String,
    back: {
      type: Boolean,
      default: true,
    },
    search: {
      type: Boolean,
      default: false,
    },
    transparent: {
      type: Boolean,
      default: false,
    },
    borderBottom: {
      type: Boolean,
      default: true,
    },
    searchVal: {
      type: String,
      default: '',
    },
  },
  methods: {
    goBack() {
      this.$router.back()
      this.$emit('left')
    },
    clickRigth() {
      this.$emit('right')
    },
    handleChange(val) {
      this.$emit('searchChange', val)
    },
  },
}
</script>
<style lang="scss" scoped>
.transparent {
  background: none;
  color: #ffffff;
  .icon-back {
    color: #fff !important;
  }
}
.defaultBg {
  background: #ffffff;
}
.navigation-bar-container {
  position: fixed;
  width: 100%;
  height: $navigationHeight;
  top: 0;
  left: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .navi-box {
    height: 100%;
    display: flex;
    align-items: center;
  }
  .title {
    font-size: 30px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    // width: 50%;
    flex-grow: 1;
    line-height: $navigationHeight;
    text-align: center;
  }
  .left-box {
    margin-left: 30px;
    flex-shrink: 0;
    width: 120px;
    .icon-back {
      font-size: 30px;
      flex-shrink: 0;
      color: #999;
    }
  }
  .right-box {
    margin-right: 27px;
    flex-shrink: 0;
    text-align: center;
    min-width: 120px;
    justify-content: flex-end;
  }
  .search {
    position: absolute;
    left: 110px;
    width: 590px;
    height: 59px;
    background: #ffffff;
    opacity: 0.5;
    border-radius: 29px;
    flex-shrink: 0;
  }
}
</style>
